<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>云修到家 - 智能助理</title>
    <style>
        :root {
            --primary: #1a1a1a;
            --secondary: #2d8cf0;
            --accent: #19be6b;
            --background: #0d1117;
            --text: #ffffff;
            --card-bg: #161b22;
        }

        body {
            font-family: 'Inter', system-ui, sans-serif;
            background: var(--background);
            margin: 0;
            color: var(--text);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .container {
            max-width: 800px;
            margin: 20px auto;
            background: var(--card-bg);
            border-radius: 16px;
            box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
            flex-grow: 1;
            display: flex;
            flex-direction: column;
        }

        .chat-container {
            flex: 1;
            padding: 24px;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            gap: 16px;
        }

        .message {
            max-width: 75%;
            padding: 16px 24px;
            border-radius: 20px;
            animation: fadeIn 0.3s ease;
            position: relative;
        }

        .ai-message {
            background: var(--primary);
            align-self: flex-start;
            border-radius: 20px 20px 20px 4px;
        }

        .user-message {
            background: var(--secondary);
            color: white;
            align-self: flex-end;
            border-radius: 20px 20px 4px 20px;
        }

        .input-area {
            padding: 20px;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            display: flex;
            gap: 12px;
            align-items: center;
        }

        select {
            padding: 10px 16px;
            border-radius: 12px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            background: var(--primary);
            color: var(--text);
            appearance: none;
            cursor: pointer;
            transition: all 0.2s;
        }

        select:hover {
            border-color: var(--secondary);
        }

        input {
            flex: 1;
            padding: 14px 20px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 12px;
            background: var(--primary);
            color: var(--text);
            font-size: 16px;
            transition: all 0.2s;
        }

        input:focus {
            outline: none;
            border-color: var(--secondary);
            box-shadow: 0 0 0 2px rgba(45, 140, 240, 0.2);
        }

        button {
            padding: 14px 28px;
            border: none;
            border-radius: 12px;
            background: var(--secondary);
            color: white;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s;
        }

        button:hover {
            opacity: 0.9;
            transform: translateY(-1px);
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .typing-indicator {
            display: none;
            padding: 16px;
            align-items: center;
            gap: 8px;
            color: rgba(255, 255, 255, 0.6);
        }

        .dot-flashing {
            position: relative;
            width: 6px;
            height: 6px;
            border-radius: 3px;
            background-color: var(--secondary);
            animation: dotFlashing 1s infinite linear;
        }

        @keyframes dotFlashing {
            0% { background-color: var(--secondary); }
            50% { background-color: rgba(45, 140, 240, 0.2); }
            100% { background-color: var(--secondary); }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="chat-container" id="chatContainer">
        <div class="message ai-message">欢迎来到硅谷到家，请问有什么可以帮助您？</div>
    </div>

    <div class="input-area">
        <select id="modelSelector">
            <option value="langchain4j">Langchain4j 模型</option>
            <option value="springAi">Spring AI 模型</option>
        </select>
        <input type="text" id="userInput" placeholder="输入消息..." />
        <button onclick="sendMessage()">发送</button>
    </div>
</div>

<script>
    const API_ENDPOINTS = {
        langchain4j: '/langchain4j/chatToAi', // 修正为小写
        springAi: '/springAi/chatToAi'
    };

    // 初始化事件监听
    document.addEventListener('DOMContentLoaded', () => {
        document.getElementById('userInput').addEventListener('keypress', (e) => {
            if (e.key === 'Enter') sendMessage();
        });
    });

    async function sendMessage() {
        const input = document.getElementById('userInput');
        const message = input.value.trim();
        if (!message) return;

        addMessage(message, 'user');
        input.value = '';

        try {
            const params = new URLSearchParams({
                userId: '1',
                message: message
            });

            const model = document.getElementById('modelSelector').value;
            const response = await fetch(`${API_ENDPOINTS[model]}?${params}`);
            const data = await response.text();

            addMessage(data, 'ai');
        } catch (error) {
            addMessage('服务暂时不可用，请稍后再试', 'system');
            console.error('API调用失败:', error);
        }
    }

    function addMessage(text, sender) {
        const container = document.getElementById('chatContainer');
        const messageDiv = document.createElement('div');
        messageDiv.className = `message ${sender}-message`;
        messageDiv.textContent = text;
        container.appendChild(messageDiv);
        container.scrollTop = container.scrollHeight;
    }
</script>
</body>
</html>
